<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link href="../css/header.css" rel="stylesheet" />
		<style>
			.mui-table-view{
				margin-top: 3.125rem;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">教练列表</h1>
		</header>
		<ul class="mui-table-view" id="table_view">
			
		</ul>
		<script src="../js/mui.js"></script>
		<script src="../js/app.js"></script>
		<script type="text/javascript">
			mui.init()
			mui.plusReady(function () {
			    mui.ajax(app.serverUrl+'/user/readCoachAll',{
			    	dataType:'json',//服务器返回json格式数据
			    	type:'post',//HTTP请求类型
			    	timeout:10000,//超时时间设置为10秒；
			    	success:function(data){
			    		console.log(JSON.stringify(data));
						setCoachs(data.data);
			    	}, 
			    	error:function(xhr,type,errorThrown){
			    		
			    	}
			    });
				mui(".mui-table-view").on('tap','.mui-table-view-cell',function(){
					var cid = this.getAttribute("id");
					console.log(cid);
					mui.openWindow({
						url:"my_caoch.html",
						id:"my_caoch.html",
						extras:{
							cid:cid
						}
					});
				})
			});
			function setCoachs(data){
				var table_view = document.getElementById("table_view");
				for(var i=0; i<data.length;i++){
					var li = document.createElement("li");
					li.className = 'mui-table-view-cell mui-media';
					li.id = data[i].cid;
					var img = document.createElement("img");
					img.className = 'mui-media-object mui-pull-left';
					if(data[i].picture == null){
						img.src = "../image/default.jpg"
					}else{
						img.src = app.serverUrl+data[i].picture;
					}
					
					li.appendChild(img);
					var coach_div = document.createElement('div');
					coach_div.className = 'mui-media-body';
					coach_div.innerHTML = '<span>'+data[i].name+'</span><p class="mui-ellipsis">'+data[i].slogan+'</p>';
					li.appendChild(coach_div);
					table_view.appendChild(li);
				}
			}
		</script>
	</body>

</html>
